package common

import (
	"lol.com/feb214-game/nest.git/log"
	"math/rand"
	"talent.com/cube/common/cxt"
	"talent.com/cube/conf/g"
)

//获取需要调控的区域
func GetControlIndex(tc *cxt.TableContext, edge int64, idRateDct map[uint64]float64) int32 {
	//过滤出需要调控的人
	var (
		maxRateUser uint64
		maxRate     float64
	)
	//map遍历本身就是随机的
	for userId, rate := range idRateDct {
		if tc.CostCache[userId] < edge {
			continue
		}
		if rate > maxRate {
			maxRate = rate
			maxRateUser = userId
		}
	}
	user := tc.Players.GetPlayer(maxRateUser)
	if user == nil || rand.Float64() > maxRate {
		return -1
	}
	var (
		maxBetIndex = int32(-1)
		maxBet      int64
	)
	//选出最大下注区域
	for idx, info := range user.BetInfo {
		if info.Total > maxBet {
			maxBet = info.Total
			maxBetIndex = idx
		}
	}
	if maxBetIndex != -1 {
		log.Info("[%v]personal tactic hits, term:%v, hit user:%v, hit index:%v, bet amount:%v",
			g.GetCodeLabel(tc.GameType), tc.TermNumber, maxRateUser, maxBetIndex, maxBet)
	}
	return maxBetIndex
}
